<?php
if(!defined('IN_IBEIKE')) {
	exit('Access Denied');
}

class table_city_twitter extends common_table
{
	public function __construct() {

		$this->_table = 'city_twitter';
		$this->_pk    = 'tid';

		parent::__construct();
	}
	public function delete_by_tid($tid){
		if(!empty($tid)){
			$arg=array($this->pk,$tid);
			return DB::delete($this->table,$arg);
		}
		return false;
	}
	public function fetch_all_by_pk($tid){
		if(!empty($tid) && $tid){
			return DB::fetch_all('SELECT * FROM %t WHERE '.$this->_pk.'=%s',array($this->_table,$tid));//返回数组包含各个字段的值
		}
		return false;
	}
	public function delete_all_by_tid($tid,$limit="",$unbuffered = true){//按主键删除
		if(!empty($tid) && $tid){
			$condition=$this->_pk."='".$tid."'";
			return DB::delete($this->_table,$condition,limit,$unbuffered = true);//返回受影响的行数
		}
		return false;
	}
	public function update_by_tid($tid,$data,$unbuffered = false, $low_priority = false){
		if(!empty($tid) && !empty($data)){
			$condition=$this->_pk."='".$tid."'";
			return DB::update($this->_table,$data,$condition,$unbuffered,$low_priority);//返回前一次 MySQL 操作所影响的记录行数
		}
		return false;
	}
	public function insert($data, $return_insert_id = false, $replace = false, $silent = false){
		if(!empty($data)){
			return DB::insert($this->_table,$data, $return_insert_id,$replace,$silent);//返回上一步 INSERT 操作产生的 ID
		}
		return false;
	
	}
	public function update_intfield_chage_by_pk($tid,$fielddata,$order){//$fielddata是键为字段,值为修改的数目,$order为1增加0减
		if(!empty($tid) && !empty($field) && !empty($order)){
			$old_num=self::get_intfield_num_by_pk($tid,$fielddata);//查询该主键的数字字段值,返回数组
			if($old_num!=false){
				foreach ($fielddata as $k => $v){
				if($order==1){
					$old_num[$k]=$old_num[$k]+$v;
				}else{
					$old_num[$k]=$old_num[$k]-$v;
				}
				}
			}else{
				return false;
			}
			$condition="where ".$this->_pk."='".$tid."'";
			return DB::update($this->_table,$old_num,$condition);//更新数据
		}else{
			return false;
		}
	}
	public static function get_intfield_num_by_pk($tid,$fielddata){//按主键查询数字类的字段的值为多少
		if(!empty($tid) && !empty($fielddata)){
			$sql="select %f from ".$this->_table." where ".$this->_pk."='".$tid."'";
			$num=DB::fetch_first($sql,$fielddata);
			return $num;
		}else{
			return false;
		}
	}
	



}
?>